import DomCreate from './domCreate';

export default class DropMovingDom {
	static MovingDom: HTMLElement = DomCreate.dealDropHover()
	static showStatus = false
	static timeLimit = 200
	static timeout: number

	static showDom(): void {
	    if (this.timeout) {
	        clearTimeout(this.timeout);
		    this.timeout = 0;
	    }
	    if (!this.showStatus) {
	        document.body.append(this.MovingDom);
	        this.showStatus = true;
	    }
	}

	static hideDom(): void {
	    if (this.timeout) {
	        return;
	    }
	    this.timeout = window.setTimeout(() => {
	        if (this.showStatus) {
	            document.body.removeChild(this.MovingDom);
	            this.showStatus = false;
	            this.timeout = 0;
	        }
	    }, this.timeLimit);
	}

	static moveDom(top: number, left: number, width: number): void {
	    this.setStyle('top', top + 'px');
	    this.setStyle('left', left + 'px');
	    this.setStyle('width', width + 'px');
	}

	/**
	 * 设置样式封装
	 * @param key
	 * @param value
	 */
	private static setStyle(key: string, value: string): void {
	    this.MovingDom.style[key] = value;
	}
}
